<?php
/**
 * Alpha-numeric rule
 * Validates that a value is alphabetical. Can optionally allow whitespace and
 * underscores.
 *
 * @package     Q-Validate
 * @subpackage  Rules
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Alpha.php 37 2010-12-23 02:38:44Z luke.visinoni $
 */
class Q_Rule_Alpha extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     */
    protected $_params = array(
        'whitespace' => false,
        'underscore' => false,
    );
    
    public function isValid($value) {
    
        $whitespace = ($this->getParam('whitespace')) ? '\s' : '';
        $underscore = ($this->getParam('underscore')) ? '_' : '';
        $pattern = "/^[a-z{$whitespace}{$underscore}]+$/i";
        return $this->_validatePattern($pattern, $value);
    
    }

}
